package dgo.interval;
import dgo.Callback;

public class Act extends Interval{
  private Callback _callback;
  private Object _argument;
 
  public Act(int duration){
    this.duration = duration;
    _callback = null;
    _argument = null;
  }
  
  public Act(Callback callback){
    this.duration = 1;
    _callback = callback;
    _argument = null;
  }
  
  public Act(int duration, Callback callback){
    this.duration = duration;
    _callback = callback;
    _argument = null;
  }
  
  public Act(int duration, Object arguments, Callback callback){
    this.duration = duration;
    _callback = callback;
    _argument = arguments;
  }
  
  public boolean call(IntervalNode node){
    if(this.duration == 0) return false;
    int d;
    if(this.duration == -1){
      d = node.parent.duration;
    }else{
      d = this.duration;
    }

    if((node.counter >= d)) return false;
    node.counter++;
    
    if(_callback != null)_callback.call(node.counter, _argument);
    return true;
  }
}
